window.addEventListener('load', function () {
    var mySwiper = new Swiper('.swiper', {
        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },

    })
    //海量Api注册事件
    let a = this.document.querySelectorAll('#Api-list ul li a');
    let oldUrl = ''
    a.forEach(function (v) {
        v.addEventListener('mouseover', function () {
            this.style.backgroundColor = '#1271ef',
                this.lastElementChild.style.color = '#ffffff'
            let thisUrl = this.firstElementChild.src
            oldUrl = thisUrl
            let index = thisUrl.lastIndexOf('/')
            let newUrl = thisUrl.substring(index + 1)
            this.firstElementChild.src = `./imgs/${newUrl.split('.')[0]}-c.svg`

        })
        v.addEventListener('mouseout', function () {
            this.style.backgroundColor = '',
                this.lastElementChild.style.color = ''
            this.firstElementChild.src = oldUrl
        })
    })
    //独角兽
    let items = document.querySelectorAll('.items');
    let index = 0;
    items[index].style.display = 'block';
    window.setInterval(function () {
        items[index].style.display = 'none';
        index++;
        if (index == items.length) {
            index = 0
        }
        items[index].style.display = 'block';
    }, 2000)
    //返回顶部
    let returnTop = document.getElementById('ret-btn');
    // console.log(returnTop)
    window.addEventListener('scroll', function () {
        let H = document.documentElement.scrollTop;
        if (H >= 200) {
            returnTop.style.display = "block"
        }
        else {
            returnTop.style.display = "none"
        };
    })
    let timeId = null;
    returnTop.addEventListener('click', function () {
        window.clearInterval(timeId)
        timeId = window.setInterval(function () {
            let H = document.documentElement.scrollTop;
            console.log(H)
            document.documentElement.scrollTop = H - 50;
            if (H <= 0) {
                window.clearInterval(timeId)
            }
        }, 10)
    })
})